package com.senbai.springlearning.redislearn;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class RedisServer {

    static List<Socket> socketList = new ArrayList();
    static byte[] bs = new byte[1024];
    public static void main(String args[]) throws IOException {
        ServerSocket serverSocket = new ServerSocket(6379);

        while(true) {
            for (Socket socket : socketList) {
                int read = socket.getInputStream().read(bs);
                if (read > 0) {
                    System.out.println(bs.toString());
                }
            }

            Socket socketClient = serverSocket.accept();//阻塞，
            if(socketClient != null){
                socketList.add(socketClient);
            }
        }
    }
}
